import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './plugins/tui-editor.js'
import './plugins/ant-design-vue.js'
import './assets/global.css'
import globalVal from './assets/globalValues.js'
import './assets/iconfont/iconfont.css'
import moment from 'moment'
import axios from 'axios'
import EnvConf from "./env-conf.js"
import PubConf from "./pub-conf.js"

//挂载
const conf = EnvConf
Vue.prototype.$oss = conf.OssUrl
Vue.prototype.$uploadServer = conf.FileUploadApi
moment.locale('zh-cn')
Vue.prototype.$moment = moment
Vue.prototype.$gval = globalVal

axios.defaults.baseURL = conf.LogicServer
axios.interceptors.request.use(config => {
  let token = window.localStorage.getItem('token');
  if (token) {
      config.headers.Authorization = token;
  }
  console.log(config);
  return config
})

//响应拦截获取token
axios.interceptors.response.use(response => {
  if (response.headers.token) {
      window.localStorage.setItem('token', response.headers.token)
      console.log(response.headers.token);
  }
  return response.data
}, error => {
  console.log(error)
  const {
      response
  } = error
  if (!response) {
      Vue.prototype.$msg.error('网络错误')
      return Promise.reject(error)
  }
  switch (response.status) {
      case 404:
          Vue.prototype.$msg.error('服务器资源未找到')
          break
      case 500:
          Vue.prototype.$msg.error('服务器繁忙')
          break
  }

  return Promise.reject(error)
})
Vue.prototype.$http = axios



Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
